﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NCLCustomerManagement.DataAccess.Products;
using NCLCustomerManagement.DataTransferObjects.Product;

namespace NCLCustomerManagement.BusinessLogic.Products
{
    public class ProductBC : BaseBC, IProductBC
    {
        private IProductRepository _repo;

        public ProductBC(IProductRepository repo)
        {
            _repo = repo;
        }
        public IEnumerable<ProductDTO> GetAllProducts()
        {
            return _repo.GetAllProducts();
        }

        public override My.DataAccess.Core.IBaseRepository<DTO> GetRepository<DTO>()
        {
            return _repo as My.DataAccess.Core.IBaseRepository<DTO>;
        }


        public void AddProduct(ProductDTO dto)
        {
            _repo.AddProduct(dto);
        }

        public void UpdateProduct(ProductDTO dto)
        {
            _repo.UpdateProduct(dto);
        }

        public void DeleteProduct(int productId)
        {
            _repo.DeleteProduct(productId);
        }


        public ProductDTO GetProduct(int id)
        {
            return _repo.GetAllProducts().SingleOrDefault(e => e.Id == id);
        }


        public int GetProductCountOf(int categoryId)
        {
            return _repo.GetProductCountOf(categoryId);
        }
    }
}
